package com.cqc.canvasdemo01;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by ${cqc} on 2017/7/20.
 */

public class DrawView extends View {

    public DrawView(Context context) {
        super(context);
    }

    public DrawView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    //api>=21
//    public DrawView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
//        super(context, attrs, defStyleAttr, defStyleRes);
//    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //创建画笔并设置
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);//
        paint.setStrokeWidth(6.0f);//画笔宽度
        paint.setColor(Color.RED);//颜色
        paint.setAntiAlias(true);//消除锯齿


        canvas.drawText("drawText", 10, 20, paint);
        canvas.drawCircle(400, 50, 20, paint);
        canvas.drawLine(30, 50, 300, 50, paint);
        canvas.drawLine(30, 50, 300, 150, paint);

        RectF oval = new RectF(50, 20, 180, 90);
        canvas.drawArc(oval,20,30,true,paint);
    }
}
